package com.tim.ying.zk.service.impl;

import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.ZooKeeper;

import com.tim.ying.zk.lock.DistributeLock;
import com.tim.ying.zk.util.ZKUtils;

public class DistributeServiceImpl {
	
	public void doService() throws KeeperException, InterruptedException{
		ZooKeeper zk = ZKUtils.createServer();
		DistributeLock lock = new DistributeLock(zk);
		ZKUtils.createPersisitentNode(zk, lock.GROUP_PATH, Thread.currentThread().getName(), ZooDefs.Ids.OPEN_ACL_UNSAFE);
		if(lock.getLock()){
			lock.doWorker();
		}
	}
}
